package com.github.androiddevelopmentframework.mvp.presenter;

import com.github.androiddevelopmentframework.mvp.baiduInterface.BaiduInterface;
import com.github.freewu.mvp.presenter.HttpPresenter;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by free on 16-10-18.
 */

public class BaiduPresenter extends HttpPresenter<BaiduInterface.ViewInterface,BaiduInterface.ApiServer> {
    public BaiduPresenter(BaiduInterface.ViewInterface mView) {
        super(mView);
    }

    @Override
    public Class<BaiduInterface.ApiServer> getApiServerClass() {
        return BaiduInterface.ApiServer.class;
    }
    public void request(){
        getView().getStatusController().showLoadingView();

        getApiServer().request().enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful()) {
                    String string = response.body();

                    getView().setText(string);

                    getView().getStatusController().showNormalView();
                }else{
                    getView().getStatusController().showErrorView();
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                getView().getStatusController().showReloadView();
            }
        });
    }
}
